<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">util</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">require</span><span class="PUNC">(</span><span class="STRN">'util'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>  2</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">mongoose</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">require</span><span class="PUNC">(</span><span class="STRN">'mongoose'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>  3</span> 
<span class='line'>  4</span> </span><span class="COMM">//var ModelManager = require('./ModelManager');</span><span class="WHIT">
<span class='line'>  5</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">TaskManager</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">require</span><span class="PUNC">(</span><span class="STRN">'./TaskManager'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>  6</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">ViewController</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">require</span><span class="PUNC">(</span><span class="STRN">'./ViewController'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>  7</span> 
<span class='line'>  8</span> </span><span class="COMM">/**
<span class='line'>  9</span>  * 
<span class='line'> 10</span>  * Module for interfacing with embeded TCP/IP hardware controller/sensors.
<span class='line'> 11</span>  * Includes a web GUI user interface, periodic task manager, MongoDB connection,
<span class='line'> 12</span>  * and device access methods
<span class='line'> 13</span>  * 
<span class='line'> 14</span>  * @class Server
<span class='line'> 15</span>  * @author jmanero
<span class='line'> 16</span>  * 
<span class='line'> 17</span>  * @requires util
<span class='line'> 18</span>  * 
<span class='line'> 19</span>  * @requires TaskManager
<span class='line'> 20</span>  * @requires ModelManager
<span class='line'> 21</span>  * @requires ViewController
<span class='line'> 22</span>  * 
<span class='line'> 23</span>  * @constructor
<span class='line'> 24</span>  * @param {Function} callback
<span class='line'> 25</span>  * 
<span class='line'> 26</span>  */</span><span class="WHIT">
<span class='line'> 27</span> </span><span class="NAME">server</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">callback</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 28</span> </span><span class="WHIT">	</span><span class="NAME">model</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 29</span> 
<span class='line'> 30</span> </span><span class="WHIT">	</span><span class="COMM">/**
<span class='line'> 31</span> 	 * Manage periodic daemon tasks
<span class='line'> 32</span> 	 * 
<span class='line'> 33</span> 	 * @type TaskManager
<span class='line'> 34</span> 	 * @memberOf Server
<span class='line'> 35</span> 	 */</span><span class="WHIT">
<span class='line'> 36</span> </span><span class="WHIT">	</span><span class="NAME">server.taskManager</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">TaskManager</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 37</span> </span><span class="WHIT">		</span><span class="NAME">mongoose.connect</span><span class="PUNC">(</span><span class="STRN">'mongodb://127.0.0.1/Control'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 38</span> </span><span class="WHIT">		</span><span class="NAME">server.Models</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 39</span> </span><span class="WHIT">		</span><span class="NAME">require</span><span class="PUNC">(</span><span class="STRN">'./Models/Device'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 40</span> </span><span class="WHIT">		</span><span class="NAME">require</span><span class="PUNC">(</span><span class="STRN">'./Models/Port'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 41</span> </span><span class="WHIT">		
<span class='line'> 42</span> 
<span class='line'> 43</span> 		</span><span class="NAME">model.Device.startup</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 44</span> </span><span class="WHIT">		</span><span class="NAME">this.on</span><span class="PUNC">(</span><span class="STRN">'LocateDevice'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 45</span> </span><span class="WHIT">			</span><span class="NAME">model.Device.locate</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 46</span> </span><span class="WHIT">		</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 47</span> </span><span class="WHIT">		</span><span class="NAME">this.addEmitter</span><span class="PUNC">(</span><span class="STRN">'LocateDevice'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">10000</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 48</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 49</span> </span><span class="WHIT">	
<span class='line'> 50</span> 	
<span class='line'> 51</span> 
<span class='line'> 52</span> 	</span><span class="COMM">/**
<span class='line'> 53</span> 	 * Manage all data models
<span class='line'> 54</span> 	 * 
<span class='line'> 55</span> 	 * @type ModelManager
<span class='line'> 56</span> 	 * @memberOf Server
<span class='line'> 57</span> 	 */</span><span class="WHIT">
<span class='line'> 58</span> </span><span class="COMM">//	server.modelManager = new ModelManager(server, function() {</span><span class="WHIT">
<span class='line'> 59</span> </span><span class="COMM">//		this.add('Device');</span><span class="WHIT">
<span class='line'> 60</span> </span><span class="COMM">//		this.add('Port');</span><span class="WHIT">
<span class='line'> 61</span> </span><span class="COMM">//		</span><span class="WHIT">
<span class='line'> 62</span> </span><span class="COMM">//		/**</span><span class="WHIT">
<span class='line'> 63</span> </span><span class="COMM">//		 * Check for devices every 10 seconds</span><span class="WHIT">
<span class='line'> 64</span> </span><span class="COMM">//		 * </span><span class="WHIT">
<span class='line'> 65</span> </span><span class="COMM">//		 * @event</span><span class="WHIT">
<span class='line'> 66</span> </span><span class="COMM">//		 * @memberOf Server#TaskManager</span><span class="WHIT">
<span class='line'> 67</span> </span><span class="COMM">//		 */</span><span class="WHIT">
<span class='line'> 68</span> </span><span class="COMM">//		server.taskManager.on('locateDevices', function() {</span><span class="WHIT">
<span class='line'> 69</span> </span><span class="COMM">//			server.Models.Device.locate();</span><span class="WHIT">
<span class='line'> 70</span> </span><span class="COMM">//		});</span><span class="WHIT">
<span class='line'> 71</span> </span><span class="COMM">//		</span><span class="WHIT">
<span class='line'> 72</span> </span><span class="COMM">//		/**</span><span class="WHIT">
<span class='line'> 73</span> </span><span class="COMM">//		 * Fetch </span><span class="WHIT">
<span class='line'> 74</span> </span><span class="COMM">//		 */</span><span class="WHIT">
<span class='line'> 75</span> </span><span class="COMM">//		</span><span class="WHIT">
<span class='line'> 76</span> </span><span class="COMM">//		server.taskManager.addEmitter('locateDevices', 10000);</span><span class="WHIT">
<span class='line'> 77</span> </span><span class="COMM">//	});</span><span class="WHIT">
<span class='line'> 78</span> 
<span class='line'> 79</span> </span><span class="WHIT">	</span><span class="COMM">/**
<span class='line'> 80</span> 	 * Manage the user interface views and routes
<span class='line'> 81</span> 	 * 
<span class='line'> 82</span> 	 * @type ViewController
<span class='line'> 83</span> 	 * @memberOf Server
<span class='line'> 84</span> 	 */</span><span class="WHIT">
<span class='line'> 85</span> </span><span class="WHIT">	</span><span class="NAME">server.viewController</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">ViewController</span><span class="PUNC">(</span><span class="NAME">server</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 86</span> </span><span class="WHIT">		</span><span class="NAME">this.add</span><span class="PUNC">(</span><span class="STRN">'SaveDevice'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 87</span> </span><span class="WHIT">		</span><span class="NAME">this.add</span><span class="PUNC">(</span><span class="STRN">'EditDevice'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 88</span> </span><span class="WHIT">		</span><span class="NAME">this.add</span><span class="PUNC">(</span><span class="STRN">'Devices'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 89</span> </span><span class="WHIT">		</span><span class="NAME">this.add</span><span class="PUNC">(</span><span class="STRN">'SavePort'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 90</span> </span><span class="WHIT">		</span><span class="NAME">this.add</span><span class="PUNC">(</span><span class="STRN">'EditPort'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 91</span> </span><span class="WHIT">		</span><span class="NAME">this.add</span><span class="PUNC">(</span><span class="STRN">'Ports'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 92</span> </span><span class="WHIT">		</span><span class="NAME">this.add</span><span class="PUNC">(</span><span class="STRN">'Dashboard'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 93</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 94</span> 
<span class='line'> 95</span> </span><span class="WHIT">	</span><span class="NAME">callback</span><span class="PUNC">(</span><span class="NAME">server</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 96</span> </span><span class="WHIT">	</span><span class="NAME">util.log</span><span class="PUNC">(</span><span class="STRN">"Started ControlServer"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 97</span> 
<span class='line'> 98</span> </span><span class="WHIT">	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 99</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>100</span> 
<span class='line'>101</span> </span><span class="NAME">exports.createServer</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">server</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>102</span> </span></pre></body></html>